// pages/vip/vip_broadcast/vip_broadcast.js
const db = wx.cloud.database({});
Page({

  /**
   * 页面的初始数据
   */
  data: {
video:{},
time:'',
bcolor:[
  '#85c1e9',' #bb8fce ','#f1948a',' #76d7c4','  #f7dc6f','#85929e ',
]
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	//   console.log(options.id)
	let res = db.collection("video").doc(options._id).get()
			.then(res => {
				console.log(res.data)
				
var timestamp = res.data._createTime
var time = this.formatDates(timestamp) //转换时间戳
            this.setData({
				video:res.data,
				time:time
			})
			})

  },
  like(){
this.setData({
  'video.like':this.data.video.like+1
})
let video = this.data.video
console.log(video)
db.collection("video").doc(video._id).update({
  data:({
    like:video.like
  })
})

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  formatDates: function (inputTime) {
	var date = new Date(inputTime);
	var y = date.getFullYear();
	var m = date.getMonth() + 1;
	m = m < 10 ? ('0' + m) : m;
	var d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	var h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	var minute = date.getMinutes();
	var second = date.getSeconds();
	minute = minute < 10 ? ('0' + minute) : minute;
	second = second < 10 ? ('0' + second) : second;
	return y + '-' + m + '-' + d;
},

})